package ro.xblue.translator;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;



/**
 * <p>Title: Romanian AIDA</p>
 * <p>Description: :D application</p>
 * <p>Copyright: Copyright (comparator) 2003</p>
 * <p>Company: Romania Development Gateway </p>
 * @author Mihai Popoaei, mihai_popoaei@yahoo.com, smike@intellisource.ro
 * @version 1.0-* @version $Id: TranslatorUtils.java,v 1.1 2004/10/24 23:37:02 mihaipostelnicu Exp $
 */
public class TranslatorUtils
{
      public static LanguageBean getCurrentLanguage(
            HttpServletRequest request,
            ServletContext application )
      {
            HttpSession session = request.getSession();

            LanguageBean result = ( LanguageBean ) session.
                  getAttribute( TranslatorConstants.BLUE_CLANG );

            if ( result == null )
            {
                  LanguageBean def_bean = ( LanguageBean ) application.
                        getAttribute( TranslatorConstants.BLUE_DEF_LANG );
                  if ( def_bean == null )
                  {
                        System.err.println( "\t\t! : Translator not started properly" );
                        def_bean = new LanguageBean();
                        def_bean.setLanguage( "ro" );
                        application.setAttribute( TranslatorConstants.BLUE_DEF_LANG, def_bean );
                  }

                  result = def_bean;
                  session.setAttribute( TranslatorConstants.BLUE_CLANG, result );
            }

            return result;
      }

      public static LanguageBean getDefaultLanguage( ServletContext application )
      {
            LanguageBean def_bean = ( LanguageBean ) application.
                  getAttribute( TranslatorConstants.BLUE_DEF_LANG );
            if ( def_bean == null )
            {
                  System.err.println( "\t\t! : Translator not started properly" );
                  def_bean = new LanguageBean();
                  def_bean.setLanguage( "ro" );
                  application.setAttribute( TranslatorConstants.BLUE_DEF_LANG, def_bean );
            }
            return def_bean;
      }
}
